package com.broada.component.flexcom.entity
{
	import com.broada.component.flexcom.manager.MapManager;
	import com.degrafa.geometry.Path;
	import com.degrafa.paint.SolidFill;
	import com.degrafa.paint.SolidStroke;
	
	import flash.events.MouseEvent;

	public class AreaItem extends AreaGroup
	{
		private var solidFill:SolidFill = new SolidFill("#0099ff");
		private var solidStroke:SolidStroke = new SolidStroke("white",1,1); 
		
		public var path:Path;
		private var pointChildren:Array;
		
		public function AreaItem(aid:String, pathData:String)
		{
			super(aid);
			path = new Path(pathData);
			path.fill = solidFill;
			path.stroke = solidStroke;
			group.geometryCollection.addItem(path);
		}
		
		public function addCircle(pi:PointItem):void{
			if(pointChildren == null){
				pointChildren = new Array();
			}
			pointChildren.push(pi.id);
			pi.group.target = MapManager.getInstance().surface;
			MapManager.getInstance().surface.graphicsCollection.addItem(pi.group);
		}
		
		public function assemblePoints():void{
			for each(var pid:String in pointChildren){
				var item:Object = MapManager.getInstance().getCircle(pid);
				if(item != null && item is PointItem){
					var pi:PointItem = item as PointItem;
					pi.group.target = group;
					MapManager.getInstance().surface.graphicsCollection.removeItem(pi.group);
					group.geometryCollection.addItem(pi.group);
				}
			}
		}
		
		public function splitPoints():void{
			for each(var pid:String in pointChildren){
				var item:Object = MapManager.getInstance().getCircle(pid);
				if(item != null && item is PointItem){
					var pi:PointItem = item as PointItem;
					pi.group.target = MapManager.getInstance().surface;
					group.geometryCollection.removeItem(pi.group);
					MapManager.getInstance().surface.graphicsCollection.addItem(pi.group);
				}
			}
		}
		
		override protected function mouseOverHandler(evt:MouseEvent):void{
			assemblePoints();
			super.mouseOverHandler(evt);
		}
		
		override protected function mouseOutHandler(evt:MouseEvent):void{
			splitPoints();
			super.mouseOutHandler(evt);
		}
	}
}